<template>
  <div class="vitualtopsavaters">
    <IndexMent />
    <div>
      <el-button @click="dialogVisible = true">虚拟人上传</el-button>
      <br />
      <div>努力开发中</div>
    </div>
    <el-dialog title="虚拟人上传" :visible.sync="dialogVisible" width="35%">
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
        :rules="rules"
      >
        <el-form-item label="虚拟人名称：" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>

        <!-- <el-form-item label="虚拟人头像">
       <el-upload
  class="avatar-uploader"
  :on-change="coverImgs"
  multiple
  action=""
  :show-file-list="false"
  :auto-upload="false"
  :drag="true"
  accept=".jpg,.png"
  >
   <img v-if="coverUrl" :src="coverUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
</el-upload>
    </el-form-item> -->
        <el-form-item label="虚拟人整体照片：" prop="staticImg">
          <el-upload
            class="avatar-uploader"
            :on-change="staticImgs"
            multiple
            action=""
            :show-file-list="false"
            :auto-upload="false"
            :drag="true"
            accept=".jpg,.png"
          >
            <!-- <img  :src="imageUrl" > -->

            <!-- <div  class="avatar demo-image__preview"> -->
            <el-image
              v-if="imageUrl"
              style="width: 60%; height: 100%"
              :src="imageUrl"
            >
            </el-image>
            <!-- </div> -->

            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item label="虚拟人背景颜色：" prop="mouthColor">
          <el-input v-model="ruleForm.mouthColor"></el-input>
        </el-form-item>
        <el-form-item label="虚拟人视频：" prop="video">
          <el-upload
            class="avatar-uploader"
            multiple
            action=""
            :show-file-list="false"
            :auto-upload="false"
            :drag="true"
            :on-change="videos"
            accept=".mp4"
          >
            <!-- <video autoplay controls  :src="videoUrl" class="avatar"/> -->

            <video
              v-if="videoUrl"
              :src="videoUrl"
              width="100%"
              height="100%"
              autoplay
              controls
            ></video>

            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            <div slot="tip" class="el-upload__tip">
              只能上传mp4文件
              <span style="color: red">建议上传小于1080p的文件</span>
            </div>
          </el-upload>
        </el-form-item>
                <el-form-item label="视频帧率" prop="fps">
          <el-input v-model.number="ruleForm.fps"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisibles('ruleForm')"
            >确 定</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    <h1>Page not found.</h1>
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="1226.887px"
      height="908px"
      viewBox="0 0 1226.887 908"
    >
      <g id="water">
        <path
          id="leftWater"
          fill="#00B6FF"
          d="M1226.887,908H1887V330.333c0,0-17.78-23.951-43.113-23.951s-50.667,32.724-144.667,32.724
		s-99.333-32.724-177.333-32.724s-76.667,32.724-172,32.724s-166.77-31.173-218.174-31.173c-73.012,0-73.012,33.725-146.023,33.725
		c-73.008,0-73.008-33.725-146.012-33.725c-73.011,0-73.011,33.725-146.019,33.725c-73.005,0-73.005-33.725-146.003-33.725
		c-73.006,0-73.006,33.725-146.016,33.725c-73.008,0-73.008-33.725-146.012-33.725c-73.001,0-73.001,33.725-146.005,33.725
		c-57.429,0-71.001-22.575-109.622-30.845c0,0-0.113-4.957-45.113-4.385s-83,24.505-129,26.572s-64.812-6.149-116.033-9.751
		c-49.875-3.507-64.967-15.889-134.967-16.821s-237,55.572-237,55.572l2,547H0L1226.887,908z"
        />
        <path
          id="rightWater"
          opacity="0.7"
          fill="#00B6FF"
          d="M1887,908V607.943V307.886c-27.059,3.017-42.916,10.22-60.79,16.67
		s-37.766,12.146-72.893,12.146c-40.485,0-60.728-7.568-80.971-15.138c-20.243-7.568-40.486-15.137-80.973-15.137
		c-40.483,0-60.725,7.568-80.968,15.137c-20.242,7.569-40.485,15.138-80.971,15.138c-40.484,0-60.726-7.568-80.967-15.138
		c-20.241-7.568-40.482-15.137-80.963-15.137c-40.486,0-60.729,7.568-80.971,15.137c-20.243,7.569-40.485,15.138-80.97,15.138
		c-40.486,0-60.729-7.568-80.972-15.138c-20.242-7.568-40.483-15.137-80.967-15.137c-40.482,0-60.724,7.568-80.966,15.137
		c-20.242,7.569-40.483,15.138-80.968,15.138c-31.848,0-72.604-26.805-121.579-27.69s-54.279,6.633-78.847,11.038
		c-44.312,7.945-66.016,18.911-103.266,19.056s-83.045-30.716-137.045-29.648S228.299,337,185.887,337
		c-42,0-106.792-29.067-158.5-29.067c-32.333,0-109,31.173-188,31.173s-75-32.724-158.5-32.724s-92.5,32.724-184.5,32.724
		s-158.5-32.724-158.5-32.724l1.984,604.087L660.113,909l613.444-1H1887z"
        />
      </g>
      <g id="squidBack">
        <path
          id="tent1"
          fill="#005FB8"
          d="M432.199,644.237c0,0,1.444,0.534,4.153,1.536c36.663,17.052,47.713,53.916,38.136,80.266
		c-0.885,2.635,0.001,0.119-7.069,19.606c-8.573,23.632-4.604,12.438-24.73,69.645c-2.028,5.766-4.04,11.485-6.028,17.137
		c-3.471,9.87-13.107,34.064-11.154,62.421c0.298,4.38,0.888,8.789,1.758,13.152h82.876c-0.581-0.31-1.167-0.612-1.733-0.943
		c-1.711-1.018-3.317-2.133-4.805-3.312c-20.484-16.15-0.4-71.467-0.652-70.467c2.937-11.676,5.919-23.535,8.903-35.396
		c13.658-53.723,16.46-59.657,17.403-75.706c0.936-14.937-1.134-29.403-5.257-42.254c-6.648-21.014-19.66-40.621-39.378-55.898
		c-12.336-9.366-25.246-15.318-39.856-19.242c-10.208-2.706-21.08,2.722-24.817,12.828
		C415.977,628.345,421.462,640.267,432.199,644.237z"
        />
        <path
          id="tent2"
          fill="#005FB8"
          d="M698.706,908h72.34c-1.096-0.779-2.206-1.641-3.331-2.599c-3.384-2.985-6.706-6.95-9.616-11.765
		c-12.827-22.479-4.942-43.119-0.125-64.463c2.116-9.53,5.021-21.135,6.943-28.909c8.716-34.801,18.933-57.854,6.827-90.303
		c-6.408-17.491-18.544-34.052-36.326-46.753c-0.493-0.351-0.748-0.532-0.748-0.532c-7.43-5.265-17.812-3.919-23.585,3.278
		c-5.994,7.472-4.796,18.388,2.675,24.382l0.591,0.475c0,0,0.244,0.195,0.716,0.574c14.119,11.318,23.536,29.184,21.693,47.66
		c-0.713,7.543-1.618,8.415-16.222,47.066c-20.226,54.427-27.044,67.854-26.043,94.698C694.838,890.285,696.331,899.419,698.706,908
		z"
        />
      </g>
      <g id="squidFront">
        <path
          id="tent3"
          fill="#2D3965"
          d="M644.99,730.776c0.595,1.157,1.192,2.271,1.83,3.323c6.461,10.951,11.392,16.271,17.344,22.202
		c6.868,6.811,17.979,7.189,25.26,0.64c7.546-6.789,8.161-18.41,1.372-25.956c0,0-0.402-0.447-1.183-1.314
		c-16.246-18.078-20.826-44.066-10.578-67.113c10.79-23.356,34.057-36.631,57.678-35.07c35.636,1.978,59.734,35.494,52.137,68.086
		c-4.876,21.281-10.381,21.927-79.792,86.332c-19.512,18.122-28.601,25.433-40.788,45.235c-1.229,2.223-2.474,4.358-3.563,6.674
		c-10.297,20.577-13.039,45.029-4.896,69.393c0.556,1.662,1.143,3.253,1.746,4.793h84.269c-1.585-2.688-3.545-5.213-5.897-7.487
		l-0.489-0.472c-19.034-18.422-23.844-33.269-4.432-54.468c46.325-50.523,81.968-79.772,95.599-103.887
		c12.249-21.862,17.11-48.022,12.09-74.304c-9.789-50.995-54.321-87.492-104.955-87.36
		c-61.184-0.297-110.777,52.717-103.774,114.993C635.625,709.523,640.12,721.613,644.99,730.776z"
        />
        <path
          id="tent4"
          fill="#2D3965"
          d="M660.793,908c2.253-7.773,3.738-15.787,4.461-23.756c1.413-15.434,0.156-27.82-2.252-42.207
		c-2.122-13.193-7.265-27.879-10.179-36.745c-2.408-7.325-4.846-14.741-7.303-22.215c-4.912-14.938-9.902-30.112-14.893-45.287
		c-22.985-69.287-22.439-65.345-24.909-75.007c-3.308-13.814-3.245-27.866-0.034-41.389c6.995-30.237,29.952-55.992,62.892-67.404
		c8.504-2.938,13.787-11.751,12.042-20.846c-1.913-9.979-11.553-16.517-21.531-14.604l-0.584,0.111
		c-33.272,6.387-60.368,23.244-79.792,46.13c-9.368,11.052-18.096,24.585-24.294,40.48c-6.248,15.835-10.077,33.979-10.106,53.095
		c-0.106,19.916,2.797,27.117,15.55,98.894c2.719,15.55,5.438,31.1,8.114,46.406c1.336,7.645,2.662,15.229,3.972,22.721
		c5.611,32.11,7.223,52.174-15.813,61.501c-22.003,8.724-36.428,2.564-55.607,20.121H660.793z"
        />
        <path
          id="tent5"
          fill="#2D3965"
          d="M379.528,740.987c31.41,31.916,17.937,18.077,59.572,61.208c6.335,6.562,12.564,13.014,18.661,19.329
		c13.024,13.485,35.26,33.938,33.978,57.603c-0.209,3.458-0.875,6.712-1.907,9.881c-2.295,7.052-5.856,12.384-9.219,17.11
		c-0.487,0.647-0.971,1.272-1.451,1.882h75.496c0.107-0.404,0.221-0.8,0.325-1.209c2.114-8.326,3.421-17.719,3.261-27.648
		c-0.156-9.925-1.917-20.271-5.093-30.196c-13.417-41.985-55.82-74.435-92.669-108.668c-19.715-18.321-10.236-9.61-42.628-39.146
		c-11.349-10.349-29.472-25.52-32.859-57.594c-4.255-43.684,26.915-81.023,67.837-88.431c25.528-4.499,51.999,2.554,72.586,21.087
		c0.881,0.793,1.336,1.203,1.336,1.203c7.206,6.462,18.331,6.277,25.272-0.641c7.19-7.165,7.21-18.802,0.044-25.992
		c-37.368-37.493-87.944-46.48-131.987-31.007c-50.09,17.689-87.94,66.966-85.534,126.883
		C336.678,688.176,354.184,715.236,379.528,740.987z"
        />
      </g>
      <g id="bubbles">
        <circle fill="#00AEF7" cx="623.879" cy="408.974" r="4.913" />
        <circle fill="#00AEF7" cx="545.501" cy="747.773" r="4.913" />
        <circle fill="#00AEF7" cx="592.4" cy="627.177" r="7.37" />
        <circle fill="#00AEF7" cx="504.856" cy="602.164" r="7.37" />
        <circle fill="#006FCF" cx="530.887" cy="614.999" r="5.527" />
        <circle fill="#006FCF" cx="686.885" cy="504.999" r="3.825" />
        <circle fill="#FFFFFF" cx="622.773" cy="795.12" r="3.685" />
        <circle fill="#006FCF" cx="472.697" cy="527.126" r="3.685" />
      </g>
      <g id="bubbles2">
        <path
          fill="#006FCF"
          d="M647.786,752.464c-2.035,0-3.685-1.65-3.685-3.686C644.101,738.023,658.502,752.464,647.786,752.464z"
        />
        <circle fill="#006FCF" cx="722.824" cy="556.717" r="3.685" />
        <circle fill="#006FCF" cx="610.195" cy="430.975" r="3.685" />
        <circle fill="#FFFFFF" cx="449.917" cy="538.738" r="6.142" />
        <circle fill="#FFFFFF" cx="616.746" cy="470" r="6.142" />
        <circle fill="#FFFFFF" cx="585.701" cy="684.795" r="8.061" />
        <circle fill="#FFFFFF" cx="640.192" cy="818.792" r="8.061" />
      </g>
      <g id="bottle">
        <path
          fill="#FFFFFF"
          d="M589.59,332.821c6.882,1.926,13.794,3.701,20.812,5.024c4.953,0.352,9.882,0.345,14.836-0.011
		c1.066-0.204,2.126-0.431,3.187-0.659c5.371-10.27,9.474-18.127,9.509-18.232l0.093-0.027c8.667-16.526-5.036-10.668,5.175-32.325
		l10.401-19.835l-13.808-7.24l-10.467,19.961c-11.961,20.557-14.931,6.019-23.58,22.513l0.029,0.092
		C605.686,302.203,597.821,317.157,589.59,332.821z"
        />

        <rect
          x="641.23"
          y="254.555"
          transform="matrix(0.8856 0.4644 -0.4644 0.8856 196.4175 -269.9889)"
          fill="#C7A66F"
          width="10.258"
          height="18.461"
        />
        <path
          fill="#FFFFFF"
          d="M653.436,273.045c-0.365,0.695-1.232,0.967-1.927,0.602l-16.188-8.488
		c-0.695-0.365-0.966-1.232-0.602-1.928l2.083-3.972c0.365-0.695,1.232-0.966,1.927-0.601l16.188,8.489
		c0.695,0.364,0.966,1.23,0.602,1.926L653.436,273.045z"
        />
        <path
          fill="#005FB8"
          d="M579.017,352.949c-4.666,8.884-8.058,15.347-8.058,15.347c-1.54,2.937-0.408,6.566,2.529,8.106
		l21.672,11.364c2.937,1.54,6.566,0.408,8.106-2.529c0,0,9.991-19.073,19.247-36.759
		C608.212,351.517,593.521,353.153,579.017,352.949z"
        />
      </g>
      <g id="numbers">
        <path
          fill="#FFFFFF"
          d="M571.062,450.443l-2.667-5.084l2.156-17.892l6.726-3.528l7.123,13.576l2.449-1.284l2.406,4.587
		l-2.448,1.285l2.179,4.154l-6.043,3.17l-2.147-4.091L571.062,450.443z M578.76,440.555l-3.14-5.982
		c-0.113-0.218-0.229-0.513-0.497-1.4c-0.217-0.716-0.42-1.479-0.528-2.213c0.044,0.688,0.075,1.424,0.061,2.301l-0.001,0.751
		l-0.025,0.251l-0.767,8.862L578.76,440.555z"
        />
        <path
          fill="#006FCF"
          d="M594.011,506.102c0.185-0.711,0.411-1.449,0.63-2.151c2.141-6.315,5.303-8.751,10.062-8.423
		c7.289,0.477,10.628,5.32,9.15,13.397c-0.276,1.484-0.645,2.906-1.114,4.304c-2.654,7.737-7.898,10.394-14.502,7.273
		c-4.313-2.057-5.904-5.687-4.719-12.215C593.677,507.533,593.827,506.812,594.011,506.102z M600.506,509.085
		c-0.353,1.644-0.47,2.373-0.544,3.077c-0.264,3.114,0.736,4.42,2.512,4.266c0.96-0.077,1.807-0.833,2.741-2.906
		c0.277-0.65,0.529-1.346,1.018-2.954c0.288-0.829,0.489-1.608,0.632-2.44c0.354-1.644,0.471-2.373,0.544-3.076
		c0.244-2.758-0.418-3.832-1.739-4.175c-1.288-0.333-2.388,0.285-3.514,2.814c-0.276,0.651-0.528,1.345-1.018,2.954
		c-0.139,0.398-0.244,0.805-0.35,1.211C600.684,508.262,600.578,508.669,600.506,509.085z"
        />
        <path
          fill="#006FCF"
          d="M623.107,608.756l1.129-5.63l12.941-12.54l7.447,1.494l-3.016,15.032l2.71,0.544l-1.019,5.079
		l-2.711-0.544l-0.923,4.6l-6.692-1.344l0.909-4.529L623.107,608.756z M635.314,605.922l1.33-6.625
		c0.048-0.239,0.144-0.542,0.495-1.399c0.282-0.692,0.604-1.414,0.983-2.053c-0.398,0.564-0.838,1.154-1.402,1.826l-0.474,0.583
		l-0.179,0.178l-6.176,6.401L635.314,605.922z"
        />
      </g>
    </svg>
  </div>
</template>

<script>
import { upload } from "@/api/menulist";
import IndexMent from "@/components/menu/IndexMenu.vue";
export default {
  name: "VirtualHuman",
  data() {
    var bagcolor = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("背景颜色不能为空"));
      } else {
        const is = /^[#]{1}[a-zA-Z0-9]{6}$/;
        if (is.test(value)) {
          callback();
        } else {
          callback(new Error("请输入HEX值，如#123456"));
        }
      }
    };
    return {
      url: this.$store.getters["url/urls"],
      dialogVisible: false,
      ruleForm: {
        name: "", //名字
        mouthColor: "", //背景颜色
        type: 2, //类型1虚拟人2真人
        timbreId: 1, //音色（弃用）
        cover: "", //头像（弃用）
        staticImg: "", //静态图
        video: "", //视频
        source: 2, //来源用户
        fps:null,
      },
      coverUrl: "",
      imageUrl: "",
      videoUrl: "",
      rules: {
        name: [{ required: true, message: "请填写名字", trigger: "change" }],
        mouthColor: [{ validator: bagcolor, trigger: "change" }],
        staticImg: [
          { required: true, message: "请选择静态图片", trigger: "change" },
        ],
        video: [
          { required: true, message: "请选择人物视频", trigger: "change" },
        ],
        fps:[
          { required: true, message: "请输入视频帧率", trigger: "change" },
          { type: 'number', message: '视频帧率必须为数字值'}
        ]
      },
    };
  },
  components: { IndexMent },
  methods: {
    coverImgs(file) {
      this.coverUrl = URL.createObjectURL(file.raw);
      this.ruleForm.cover = file.raw; //.raw才是二进制文件
    },
    staticImgs(file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      this.ruleForm.staticImg = file.raw; //.raw才是二进制文件
    },
    videos(file) {
      this.videoUrl = URL.createObjectURL(file.raw); // 获取URL
      this.ruleForm.video = file.raw;
    },
    dialogVisibles(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const formData = new FormData();
          formData.append("cover", this.ruleForm.cover);
          formData.append("name", this.ruleForm.name);
          formData.append("mouthColor", this.ruleForm.mouthColor);
          formData.append("description", "虚拟人描述");
          formData.append("type", this.ruleForm.type);
          formData.append("timbreId", this.ruleForm.timbreId);
          formData.append("staticImg", this.ruleForm.staticImg);
          formData.append("video", this.ruleForm.video);
          formData.append("source", this.ruleForm.source);
          formData.append("fps", this.ruleForm.fps);
          upload(formData)
            .then((res) => {
              if (res.code === 200) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.dialogVisible = false; //关闭弹出层
              } else {
                this.$message({
                  message: res.msg,
                  type: "error",
                });
              }
              //  this.dialogVisible = false //关闭弹出层
            })
            .catch((err) => {
              this.$message({
                message: err.msg,
                type: "error",
              });
              //  this.dialogVisible = false //关闭弹出层
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.top {
  height: 100%;
  box-sizing: border-box;
  width: 100%;
  .box {
    height: 100%;
    width: 100%;
    // overflow: hidden;
    overflow-y: auto;
  }
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
</style>
<style>
.vitualtopsavaters .avatar-uploader > .el-upload > .el-upload-dragger {
  width: 178px;
}
</style>
<style scoped>
body {
  background: #00e7dc;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

h1 {
  /* font-family: 'Nunito', sans-serif; */
  color: #fff;
  text-align: center;
  padding: 2em 0 0;
  opacity: 0;
}

svg {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 90%;
  width: 100%;
}
</style>